package collections;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 * User: 5
 * Date: 16-12-9
 * Time: 下午2:03
 * To change this template use File | Settings | File Templates.
 */
public class CurrentHashMapM {


    @Test
    public void test() {
//        Map<Integer, String> map = new HashMap<Integer, String>();
        Map<Integer, String> map = new ConcurrentHashMap<Integer, String>();
        //写线程
        new Thread(() -> {
            for (int i = 10; i < 20; i++) {
                map.put(i, i + "");

            }

        }).start();
        //读线程
        new Thread(() -> {
            for (Integer key : map.keySet()) {
                map.remove(key);
            }
        }).start();
        new Thread(() -> {
            for (String v : map.values()) {
                System.out.println(Thread.currentThread().getName() + "---" + v);
            }
        }).start();
    }
}
